import { arrayToObject } from '../../../../assets/js/util.js'
export default {
    data() {
        return {
            title: '实时auany创建订单流水',
            xlsxTitle: '',
            // 默认参数 和 URL
            SRC: '',
            DP: {
                p: '',
                f: ''
            },
            loading: false,
            searchable: false,
            pickerOptions: {
                shortcuts: [{
                    text: '最近一周',
                    onClick(picker) {
                        const end = new Date();
                        const start = new Date();
                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
                        picker.$emit('pick', [start, end]);
                    }
                }, {
                    text: '最近15天',
                    onClick(picker) {
                        const end = new Date();
                        const start = new Date();
                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 15);
                        picker.$emit('pick', [start, end]);
                    }
                }, {
                    text: '最近一个月',
                    onClick(picker) {
                        const end = new Date();
                        const start = new Date();
                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
                        picker.$emit('pick', [start, end]);
                    }
                }]
            },
            form: {
                date: '',

                dateStart: '',
                dateEnd: '',

                // 选择的区服
                serverid: '0',
                serverids: [],
                auanyserverid: '',
                ordertype: '',
                ordertypes: [
                    { label: '游戏内订单', value: '1' },
                    { label: '直冲订单', value: '2' },
                ],
                fulluserid: '',
                orderid: '',
                productid: '',
                roleid: ''
            },
            inputWidth: '220px',
            formLabelWidth: '100px',
            /*当前页显示数量*/
            pageSize: 10,
            /*每页显示的数量*/
            pageSizes: [10, 20, 50, 100],
            /*dataTotal表数量*/
            dataTotal: 0,
            /*表格数据*/
            realTimeServiceTableData: [],
            realTimeServiceTableDatas: [],
            /*realTimeServiceContent 的宽*/
            realTimeServiceContent: '100%',
            /*表的宽度*/
            realTimeServiceTableWidth: "100%",
            /*数据表头*/
            realTimeServiceTableHead: [
                { prop: 'innerId', label: '详细时间', width: '240' },
                { prop: 'plat', label: '服务器主机名', width: '180' },
                { prop: 'channel', label: '模块名', width: '120' },
                { prop: 'serviceArea', label: '游戏ID', width: '140' },
                { prop: 'accountId', label: 'au服务器编号', width: '180' },
                { prop: 'roleId', label: '日志id', width: '140' },
                { prop: 'roleGrade', label: '日志类型', width: '180' },
                { prop: 'VIPGrade1', label: '订单类型', width: '180' },
                { prop: 'VIPGrade2', label: '全用户名', width: '120' },
                { prop: 'VIPGrade3', label: '区服id', width: '120' },
                { prop: 'VIPGrade4', label: '角色id', width: '120' },
                { prop: 'VIPGrade5', label: '订单产品id', width: '220' },
                { prop: 'VIPGrade6', label: '订单产品数量', width: '180' },
                { prop: 'VIPGrade7', label: '订单货币类型', width: '180' },
                { prop: 'VIPGrade8', label: '订单总金额', width: '170' },
                { prop: 'VIPGrade9', label: '订单id', width: '260' },
                { prop: 'VIPGradea', label: '回调地址', width: '340' },
                { prop: 'VIPGradeb', label: '扩展字段1', width: '150' },
                { prop: 'VIPGradec', label: '扩展字段2', width: '150' }

            ],
            rules: {
                serverid: [
                    { required: true, message: '请选择区服', trigger: 'change' }
                ],
                ordertype: [
                    { required: true, message: '请选择订单类型', trigger: 'change' }
                ]
            },
            /*分页器*/
            currentPage: 1
        }
    },
    computed: {
        // xlsx(){
        // 	return this.title+'.xlsx'
        // }
    },
    methods: {
        successFun(data) {
            this.$message({
                message: data,
                type: 'success'
            });
        },
        errorFun(data) {
            this.$message.error(data);
        },
        dateChange(val) {
            var t = val.split(' - ')
            this.form.dateStart = t[0];
            this.form.dateEnd = t[1];
        },
        loads() {
            this.loading = !this.loading; //加载中
            this.searchable = !this.searchable; //查询按钮不可用
        },
        reset(form) {
            this.$refs[form].resetFields();
        },
        search(form) {
            this.$refs[form].validate((valid) => {
                if (valid) {
                    this.commitData()
                } else {
                    this.errorFun('请完善输入的值！');
                    return false;
                }
            })
        },
        commitData() {
            this.realTimeServiceTableDatas = [];
            this.realTimeServiceTableData = [];
            let obj = {
                dateStart: this.form.dateStart,
                dateEnd: this.form.dateEnd,
                serverid: this.form.serverid,
                auanyserverid: this.form.auanyserverid,
                ordertype: this.form.ordertype,
                fulluserid: this.form.fulluserid,
                roleid: this.form.roleid,
                productid: this.form.productid,
                orderid: this.form.orderid
            }
            obj = encodeURI(JSON.stringify(obj));
            this.loads(); //加载 查询按钮不可用
            this.$http.jsonp(`${this.SRC}data/get.do?p=${this.DP.p}&f=${this.DP.f}&a=search`, {
                params: { 'ps': 'params=' + obj },
            }).then(function(res) {
                this.loads();
                var data = JSON.parse(JSON.parse(res.body))
                if (parseInt(data.res) === 0) {
                    if (data.data.length == 0) {
                        this.errorFun('查询结果为空！')
                    } else {
                        this.realTimeServiceTableDatas = arrayToObject(this.realTimeServiceTableHead, data.data);
                    }
                } else {
                    this.errorFun(data.msg)
                }
                this.dataTotal = this.realTimeServiceTableDatas.length;
                this.realTimeServiceTableData = this.realTimeServiceTableDatas.slice((this.currentPage - 1) * this.pageSize, this.currentPage * this.pageSize)
            })
        },
        // 表格下载
        excel(val) {
            this.xlsxTitle = val + "-" + this.form.dateStart + "到" + this.form.dateEnd;
            this.downloadExl(this.realTimeServiceTableHead, this.realTimeServiceTableDatas, this.xlsxTitle, this.title);
        },
        /*分页器*/
        handleSizeChange(val) {
            this.pageSize = val;
            // this.getData(this.pageSize,this.currentPage)
            this.realTimeServiceTableData = this.realTimeServiceTableDatas.slice((this.currentPage - 1) * this.pageSize, this.currentPage * this.pageSize)
        },
        handleCurrentChange(val) {
            this.currentPage = val;
            // this.getData(this.pageSize,this.currentPage)
            this.realTimeServiceTableData = this.realTimeServiceTableDatas.slice((this.currentPage - 1) * this.pageSize, this.currentPage * this.pageSize)
        },
        /*获取数据*/
        getData: function() {
            this.$http.jsonp(`${this.SRC}data/get.do?p=${this.DP.p}&f=${this.DP.f}&a=initParam`, {
                params: { 'ps': '' }
            }).then(function(res) {
                var data = JSON.parse(JSON.parse(res.body))
                if (parseInt(data.res) == 0) {
                    this._dataPush(data.serverItmes, this.form.serverids)
                } else {
                    this.getErrorMsg(Number(data.res))
                }
                // this.form.channel = {label:this.form.channels[0]['label'],value:this.form.channels[0]['label']}
            })
        },
        _dataPush(firstData, lastData) {
            for (var key in firstData) {
                lastData.push({ label: key, value: firstData[key] })
            }
        },
        /*设置初始值*/
        _init() {
            window.addEventListener('resize', function() {
                /*修改表格的宽度*/
                this.realTimeServiceTableWidth = document.body.clientWidth - 240 + "px";
                this.realTimeServiceContent = document.body.clientWidth - 220 + "px";
            }.bind(this))
        },
        /*选择平台切换*/
        head_choose_plat_fun(index) {
            for (var i = 0; i < this.head_choose_plat.length; i++) {
                this.head_choose_plat[i].activeIndex = false;
            }
            this.head_choose_plat[index].activeIndex = true;
        },
        head_choose_time_fun(index) {
            for (var i = 0; i < this.head_choose_time.length; i++) {
                this.head_choose_time[i].activeIndex = false;
            }
            this.head_choose_time[index].activeIndex = true;
        },
    },
    mounted() {
        this._init()
            // 初始化URL
        this.SRC = this.$store.getters.src;
        this.DP.p = localStorage.getItem('ZULONGBIPROJECTID');
        this.DP.f = localStorage.getItem('ZULONGBIPAGEID');
        this.getData()
        this.form.date = [new Date(new Date().getTime() - 86400000), new Date()];
        // this.getData(this.pageSize,this.currentPage)
    }
}